/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov;

import net.javlov.model.Model;

/**
 * Learn a model given a fixed policy
 * 
 * @author Matthijs Snel
 *
 */
public class SimpleModelAgent<T> extends SimpleAgent<T> {
	
	protected Model m;
	
	protected State<? extends T> s;
	protected Option<T> o;
	
	public SimpleModelAgent() {
		this( new Model() );
	}
	
	public SimpleModelAgent(Model mdl) {
		m = mdl;
	}
	
	@Override
	public Action firstStep( State<? extends T> s ) {
		Action a = super.firstStep(s);
		this.s = s;
		o = currentOption;
		return a;
	}
	
	@Override
	public Action doStep( State<? extends T> s, double reward ) {
		m.count(this.s, o, reward, s);
		Action a = super.doStep(s, reward);
		this.s = s;
		o = currentOption;
		return a;
	}
	

	public Model getModel() {
		return m;
	}

	public void setModel(Model m) {
		this.m = m;
	}
	
	@Override
	public void init() {
		super.init();
		m.clear();
	}
	
	

}
